<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\TestController;
use App\Http\Middleware\Test;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\DB;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

// Route::get('/', function () {
//     return 'Welcome Laravel!';
// });


Route::get('hello', function () {
    return 'Hello Laravel!';
});

/*  组      这个prefix就是在1的后面加各种后缀       举个例子 /1/1就输出1    /1就输出默认值 */
Route::prefix('/1')->group(function(){
    Route::get('/{id?}', function ($id = '默认值') {
        echo $id;
    });
});


//post 是要用表单方式交     //get  是用地址栏后面加
// Route::post('123', function () {
//     return 'hello,world';
// });

//any是post和get两个都可以用   
// Route::any('123', function () {
//     return 'hello,world';
// });

//match 就是方法 只允许用什么方式应用

/*
在web，php路由器里的post,put,delete方法,在提交表单时候必须加上csrf参数
@csrf   //5.6版本以上
{{csrf_field()}}    //5.6版本以下

*/
// Route::match(['get','put'],'/li',function(){
//     return '只能用get和put方式';
// });


/*                      */


Route::get('username/{name}/{age}',function($name,$age){
    return '姓名'.$name.'年龄'.$age;
});
//可选参数      可选参数默认值要加的
Route::get('name/{name?}/{age?}',function($name='tom',$age='18'){
    return '姓名'.$name.'年龄'.$age;
});

//参数限制
// Route::get('age/{name?}/{age?}',function($name='tom',$age='18'){
//     return '姓名'.$name.'年龄'.$age;
// })->where(['name' => '[a-z]+','age' => '[1-9]+']);


Route::get('age/{name?}/{age?}',function($name='tom',$age='18'){
    return '姓名'.$name.'年龄'.$age;
})->where(['name' => '\w+','age' => '[1-9]+']);



/*        //命名路由                  */
Route::get('/111',function(){
    return '111';
})->name('222');

Route::get('/turn',function(){
    return redirect()->route('222');
});

//命名路由参数限制
Route::get('1/111/{id}/{name}',function($id,$name){
    return $id.$name;
})->name('333');

Route::get('/turn1',function(){
    return redirect()->route('333',['id' => '1','name' => 'user']);
});

//  控制器
// Route::get('/show/{a}','TestController@show');

Route::get('show/{a}',[TestController::class,'show']);

// 中间键
Route::get('/age/{age}','AgeController@judge')->middleware(\App\Http\Middleware\CheckAge::class);


//数组传值
Route::get('shitu/{title?}', function($title='我是标题') {
    return view('index',['title'=>$title]);
});

//with传值
Route::get('with/{title?}', function($title='我是标题') {
    return view('index')->with('title',$title);
});

//compact传值
Route::get('compact/{title?}', function($title='我是标题',$name='name') {
    return view('index',compact('title','name'));
});

//判断视图文件是否存在
Route::get('Test2', function () {
    if (view()->exists('index2'))
    {
        echo '视图存在';
    }else{
        return view('welcome');
    }
});

//函数案例
Route::get('hanshu', function () {
    $time = strtotime(now());
    return View('index1',compact('time'));
});


// Route::get('select', [TestController::class,'select']);
Route::get('insert', [TestController::class,'insert']);
Route::get('update', [TestController::class,'update']);
Route::get('select1', [TestController::class,'select1']);
Route::get('delete', [TestController::class,'delete']);
//模型
Route::get('model',[TestController::class,'model']);
Route::get('selectm',[TestController::class,'selectm']);
Route::get('updatem',[TestController::class,'updatem']);
Route::get('deletem',[TestController::class,'deletem']);

//分页数据
Route::get('fenye',[TestController::class,'fenye']);

//csrf攻击
Route::any('csrf',[TestController::class,'csrf']);

// 表单验证
Route::any('post/test',[TestController::class,'test']);

Route::any('post/post1',[TestController::class,'store']);



//项目
Route::get('create/login',[TestController::class,'loginCreate']);

Route::any('create/post',[TestController::class,'loginPost']);



Route::any('create/shouye',function(){
    return view('shouye');
});

Route::any('create/shouye1',function(){
    $control = DB::table('control')->get();
    return view('shouye1',compact('control'));
});
// ->middleware(Test::class)

Route::any('select',function(){
    return view('select');
});

Route::any('update',function(){
    return view('update');
});

Route::any('create/update',[TestController::class,'UpdateJudge']);


Route::any('add',[TestController::class,'add']);

Route::any('create/add',[TestController::class,'AddJudge']);

Route::any('create/select',[TestController::class,'SelectJudge']);

Route::any('create/delete',[TestController::class,'DeleteJudge']);

Route::any('create/exit',[TestController::class,'exit']);

Route::any('delete',function(){
    return view('delete');
});

Route::any('tiku',[TestController::class,'tiku']);

Route::get('/subject', function ()
{
    // return view('welcome');
    // return 'Welcome Laravel!';
    // return view('welcome', ['name' => 'Laravel']);
    // return view('home', ['title' => '留言板']);
    return view('tiku', ['title' => 'SQL']);
});



